package com.dtu.snapdroid;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Context;
import android.os.Environment;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.dtu.XMLExtras.ReadXML;
import com.dtu.XMLExtras.Uploader;
import com.dtu.XMLExtras.WriteXMLFilterPick;


/** Class Must extends with Dialog */
/** Implement onClickListener to dismiss dialog when OK Button is pressed */
public class FilterPicker extends Dialog implements OnItemClickListener {

	private TextView testView;
	private ListView listView;

	public FilterPicker(final Context context) {
		super(context);

		SnapMain.readXML.setTag("Tags");
		SnapMain.readXML.setAttr("Tag");
		SnapMain.readXML.setPath("http://www.loftur.com/locations/listalltags.xml");
		final ArrayList<String> itemlist  = SnapMain.readXML.getInfo();
	
		
		/** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		/** Design the dialog in main.xml file */
		setContentView(R.layout.filterpicker);
		listView = (ListView) findViewById(R.id.tagsearch);
		
		listView.setAdapter(new ArrayAdapter<String>(context, R.layout.listitemfilter, itemlist));
		listView.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
				
				WriteXMLFilterPick fp = new WriteXMLFilterPick();
				fp.createXMLfile(itemlist.get(position));
				Uploader upl = new Uploader();
				upl.send(Environment.getExternalStorageDirectory()+"/filterpick.xml", "http://www.loftur.com/uploadfilteredtag.php");
				dismiss();
				
			}
		});

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		/** When tag is clicked */
		
	}
}


